#pragma once
#include <QDialog>
#include <vector>

#include "HalconCpp.h"
#include "HShapeModel.h"
using namespace HalconCpp;
#include "opencv2/opencv.hpp"


class VisionMainWnd;
class QTableWidget;
class QGraphicsRectItem;
class QGView;

class RectangleItem;
using rectArray = std::vector<cv::Rect>;    // 矩形框数组
class ModelEditDlg :
    public QDialog
{
public:
    ModelEditDlg(QWidget* parent = nullptr);
    ~ModelEditDlg();
    
    void initLayout();

    void initRightWidget(QWidget * rightPaneWidget);

    void initTableWidget(QTableWidget* tab);
    void addResuts(HTuple modelIds, HTuple rows, HTuple cols, HTuple scales, HTuple angles, HTuple scores);

    void setMinScore(double score) { minScoreMatch_ = score; }
    double getMinScore() { return minScoreMatch_; }

public slots:
    void on_add_roi();
    void on_del_roi();

    void on_snap_image();
    void on_Set_SearchRoi();
    void on_load_model();
    void on_save_model();
    void on_analyze();
    void on_set_roi();
    void on_test();

public:
    void drawResult(QImage& src, HXLDCont& xld);
    void drawResult(cv::Mat& src, HXLDCont& xld);

protected:
    rectArray getRectArrayFromViews();
    bool createShapeModel();
    bool createShapeModel_xld();
    bool findObject(cv::Mat& src);


    QRectF getRoiRect(QString objName="roi");
    RectangleItem* getRoiRectItem(QString objName = "roi");

private:
    double minScoreMatch_ = 0.6;        // 最小匹配分数60分
    QGView* imgView_ = nullptr;
    QImage imgLoad_;
    QGraphicsRectItem* rectItem_ = nullptr;
    HRegion searchRoi_;
    HShapeModelArray mulShapeModel_;
    std::vector<HXLDCont> allModelContours_;    // 保存所有模板轮廓
};

